cd "~/Dropbox/Shared Folder - J. Ladd & M (1). Meredith/Replication Files/"
cap log close
log using "LogFiles/Table3.log", replace

clear all
set more off

mat Table3 = J(15, 4, -9)

use "RawData/anes_timeseries_cdf.dta", clear
keep if VCF0004 >= 1960

//
// Issue Positions
//

// 2-Point Scale
foreach variable of varlist VCF0805 VCF0808 VCF0816 VCF0826 VCF0828 VCF0829 {
tab `variable'
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = `variable' - 1
}

// 2-Point Scale (1 to 5)
foreach variable of varlist VCF0833 VCF0878 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 4
}

// 2-Point Scale (reversed)
foreach variable of varlist VCF0819 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' =  2 - `variable' 
}

// 3-Point Scale
foreach variable of varlist VCF0814 VCF0815 VCF0827 VCF0886 VCF0887 VCF0888 /*
*/ VCF0889 VCF0890 VCF0891 VCF0892 VCF0893 VCF0894 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 2
}

// 4-Point Scale
foreach variable of varlist VCF0837 VCF0838 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 3
}

// 4-Point Scale (1, 2, 4, 5)
foreach variable of varlist VCF0818 VCF0867a VCF0876a VCF0877a {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 7 |  /*
*/ `variable' == 8 | `variable' == 9 
replace `variable' = 0 if `variable' == 1
replace `variable' = 1/3 if `variable' == 2
replace `variable' = 2/3 if `variable' == 4
replace `variable' = 1 if `variable' == 5
}

// 5-Point Scale
foreach variable of varlist VCF0879 {
tab `variable'
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 4
}

// 5-Point Scale (reversed)
foreach variable of varlist VCF0844 {
tab `variable'
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (5 - `variable') / 4
}


// 7-Point Scale
foreach variable of varlist VCF0806 VCF0809 VCF0811 VCF0817 /*
*/ VCF0827a VCF0830 VCF0832 VCF0834 VCF0839 VCF0841 VCF0842 VCF0843 {
tab `variable' 
replace `variable' = . if `variable' == 0 | `variable' == 8 | `variable' == 9 
replace `variable' = (`variable' - 1) / 6
}

// Social Welfare Spending:
// VCF0805: Government Assistance with Medical Care
// VCF0806: Government Health Insurance Scale
// VCF0808: Guaranteed Jobs and Income
// VCF0809: Guaranteed Jobs and Income Scale
// VCF0830: Aid to Blacks Scale 
// VCF0839: Government Services-Spending Scale
// VCF0886: Federal Spending- Poor/Poor People
// VCF0887: Federal Spending- Child Care
// VCF0889: Federal Spending- Research/Fight Aids
// VCF0890: Federal Spending- Public Schools
// VCF0893: Federal Spending- The Homeless
// VCF0894: Federal Spending- Welfare 

foreach var of varlist VCF0805 VCF0806 VCF0808 VCF0809 VCF0830 VCF0839 VCF0886 /*
*/ VCF0887 VCF0889 VCF0890 VCF0893 VCF0894 {
display "`var'"
tab VCF0004 if missing(`var') == 0
}

// Other Policies:
// VCF0811: Urban Unrest Scale 
// VCF0814: Civil Rights Pushes Too Fast or Not Fast Enough
// VCF0815: Segregation or Desegregation
// VCF0816: Should Government Ensure School Integration
// VCF0817: School Busing Scale
// VCF0818: Should Government Ensure Fair Jobs/Housing for Blacks
// VCF0819: Open Housing 
// VCF0826: Did U.S. Do  Right Thing Getting Involved in War
// VCF0827: How Should  U.S. Proceed in Current War
// VCF0827a: U.S. Stand in Vietnam Scale
// VCF0828: Should Government Cut Military Spending
// VCF0829: Is the Government in Washington Too Strong
// VCF0832: Rights of the Accused Scale
// VCF0833: Favor or Oppose Equal Rights Amendment
// VCF0834: Women Equal Role Scale
// VCF0837: When Should Abortion Be Allowed
// VCF0838: By Law, When Should Abortion Be Allowed
// VCF0841: Cooperation with U.S.S.R. Scale 
// VCF0842: Environmental Regulation Scale 
// VCF0843: Defense Spending Scale
// VCF0844: How Willing Should U.S. Be to Use Military Force
// VCF0867a: Affirmative Action in Hiring/Promotion
// VCF0876a: Position on Law to Protect Homosexuals Against Discrimination
// VCF0877a: Position on Gays in the Military
// VCF0878: Should Gays/Lesbians Be Able to Adopt Children
// VCF0879: Increase or Decrease Number of Immigrants to U.S. 
// VCF0888: Federal Spending- Dealing with Crime
// VCF0891: Federal Spending- Fin Aid for  College Students
// VCF0892: Federal Spending- Federal Spending- Foreign Aid

foreach var of varlist VCF0811 VCF0814 VCF0815 VCF0816 VCF0817 VCF0818 VCF0819 /*
*/ VCF0826 VCF0827 VCF0827a VCF0828 VCF0829 VCF0832 VCF0833 VCF0834 VCF0837 VCF0838 /*
*/ VCF0841 VCF0842 VCF0843 VCF0844 VCF0867a VCF0876a VCF0877a VCF0878 VCF0879 /*
*/ VCF0888 VCF0891 VCF0892 {
display "`var'"
tab VCF0004 if missing(`var') == 0
}

egen conservatism = rmean(VCF0805 VCF0806 VCF0808 VCF0809 VCF0830 VCF0839 VCF0886 /*
*/ VCF0887 VCF0889 VCF0890 VCF0893 VCF0894 VCF0811 VCF0814 VCF0815 VCF0816 VCF0817 /*
*/ VCF0818 VCF0819 VCF0826 VCF0827 VCF0827a VCF0828 VCF0829 VCF0832 VCF0833 VCF0834 /*
*/ VCF0837 VCF0838 VCF0841 VCF0842 VCF0843 VCF0844 VCF0867a VCF0876a VCF0877a /*
*/ VCF0878 VCF0879 VCF0888 VCF0891 VCF0892)
egen welfare = rmean(VCF0805 VCF0806 VCF0808 VCF0809 VCF0830 VCF0839 VCF0886 /*
*/ VCF0887 VCF0889 VCF0890 VCF0893 VCF0894)
gen gender = VCF0834
egen other = rmean(VCF0811 VCF0814 VCF0815 VCF0816 VCF0817 /*
*/ VCF0818 VCF0819 VCF0826 VCF0827 VCF0827a VCF0828 VCF0829 VCF0832 VCF0833 /*
*/ VCF0837 VCF0838 VCF0841 VCF0842 VCF0843 VCF0844 VCF0867a VCF0876a VCF0877a /*
*/ VCF0878 VCF0879 VCF0888 VCF0891 VCF0892)

foreach var of varlist conservatism welfare gender other {
egen mean_`var' = mean(`var'), by(VCF0004)
egen sd_`var' = sd(`var'), by(VCF0004)
gen std_`var' = (`var' - mean_`var') / sd_`var'
drop mean_`var' sd_`var'
}


// Party Identification

tab VCF0301
gen partyid = 0 if VCF0301 == 1 
replace partyid = 0 if VCF0301 == 2 
replace partyid = 1/2 if VCF0301 == 3
replace partyid = 1/2 if VCF0301 == 4 
replace partyid = 1/2 if VCF0301 == 5
replace partyid = 1 if VCF0301 == 6 
replace partyid = 1 if VCF0301 == 7 

// Gender 

tab VCF0104 
gen female = (VCF0104 == 2)

gen std_welfareXfemale = std_welfare * female
gen std_genderXfemale = std_gender * female
gen std_otherXfemale = std_other * female

// 1970s
local column = 1

tab VCF0004 if VCF0004 >= 1970 & VCF0004 <= 1978 & missing(gender) == 0, gen(yrdum)
drop yrdum1

regress partyid female std_welfare std_welfareXfemale std_gender std_genderXfemale /*
*/ std_other std_otherXfemale yrdum* [pweight = VCF0009z], robust

test std_welfare + std_welfareXfemale = 0
test std_gender + std_genderXfemale = 0
test std_other + std_otherXfemale = 0

mat Table3[1, `column'] = e(N)
mat Table3[2, `column'] = _b[female]
mat Table3[3, `column'] = -_se[female]
mat Table3[4, `column'] = _b[std_welfare]
mat Table3[5, `column'] = -_se[std_welfare]
mat Table3[6, `column'] = _b[std_gender]
mat Table3[7, `column'] = -_se[std_gender]
mat Table3[8, `column'] = _b[std_other]
mat Table3[9, `column'] = -_se[std_other]
mat Table3[10, `column'] = _b[std_welfareXfemale]
mat Table3[11, `column'] = -_se[std_welfareXfemale]
mat Table3[12, `column'] = _b[std_genderXfemale]
mat Table3[13, `column'] = -_se[std_genderXfemale]
mat Table3[14, `column'] = _b[std_otherXfemale]
mat Table3[15, `column'] = -_se[std_otherXfemale]

drop yrdum*

// 1980s
local column = 2

tab VCF0004 if VCF0004 >= 1980 & VCF0004 <= 1988 & missing(gender) == 0, gen(yrdum)
drop yrdum1

regress partyid female std_welfare std_welfareXfemale std_gender std_genderXfemale /*
*/ std_other std_otherXfemale yrdum* [pweight = VCF0009z], robust

test std_welfare + std_welfareXfemale = 0
test std_gender + std_genderXfemale = 0
test std_other + std_otherXfemale = 0

mat Table3[1, `column'] = e(N)
mat Table3[2, `column'] = _b[female]
mat Table3[3, `column'] = -_se[female]
mat Table3[4, `column'] = _b[std_welfare]
mat Table3[5, `column'] = -_se[std_welfare]
mat Table3[6, `column'] = _b[std_gender]
mat Table3[7, `column'] = -_se[std_gender]
mat Table3[8, `column'] = _b[std_other]
mat Table3[9, `column'] = -_se[std_other]
mat Table3[10, `column'] = _b[std_welfareXfemale]
mat Table3[11, `column'] = -_se[std_welfareXfemale]
mat Table3[12, `column'] = _b[std_genderXfemale]
mat Table3[13, `column'] = -_se[std_genderXfemale]
mat Table3[14, `column'] = _b[std_otherXfemale]
mat Table3[15, `column'] = -_se[std_otherXfemale]

drop yrdum*

// 1990s
local column = 3

tab VCF0004 if VCF0004 >= 1990 & VCF0004 <= 1998 & missing(gender) == 0, gen(yrdum)
drop yrdum1

regress partyid female std_welfare std_welfareXfemale std_gender std_genderXfemale /*
*/ std_other std_otherXfemale yrdum* [pweight = VCF0009z], robust

test std_welfare + std_welfareXfemale = 0
test std_gender + std_genderXfemale = 0
test std_other + std_otherXfemale = 0

mat Table3[1, `column'] = e(N)
mat Table3[2, `column'] = _b[female]
mat Table3[3, `column'] = -_se[female]
mat Table3[4, `column'] = _b[std_welfare]
mat Table3[5, `column'] = -_se[std_welfare]
mat Table3[6, `column'] = _b[std_gender]
mat Table3[7, `column'] = -_se[std_gender]
mat Table3[8, `column'] = _b[std_other]
mat Table3[9, `column'] = -_se[std_other]
mat Table3[10, `column'] = _b[std_welfareXfemale]
mat Table3[11, `column'] = -_se[std_welfareXfemale]
mat Table3[12, `column'] = _b[std_genderXfemale]
mat Table3[13, `column'] = -_se[std_genderXfemale]
mat Table3[14, `column'] = _b[std_otherXfemale]
mat Table3[15, `column'] = -_se[std_otherXfemale]

drop yrdum*

// 2000s
local column = 4

tab VCF0004 if VCF0004 >= 2000 & VCF0004 <= 2012 & missing(gender) == 0, gen(yrdum)
drop yrdum1

regress partyid female std_welfare std_welfareXfemale std_gender std_genderXfemale /*
*/ std_other std_otherXfemale yrdum* [pweight = VCF0009z], robust

test std_welfare + std_welfareXfemale = 0
test std_gender + std_genderXfemale = 0
test std_other + std_otherXfemale = 0

mat Table3[1, `column'] = e(N)
mat Table3[2, `column'] = _b[female]
mat Table3[3, `column'] = -_se[female]
mat Table3[4, `column'] = _b[std_welfare]
mat Table3[5, `column'] = -_se[std_welfare]
mat Table3[6, `column'] = _b[std_gender]
mat Table3[7, `column'] = -_se[std_gender]
mat Table3[8, `column'] = _b[std_other]
mat Table3[9, `column'] = -_se[std_other]
mat Table3[10, `column'] = _b[std_welfareXfemale]
mat Table3[11, `column'] = -_se[std_welfareXfemale]
mat Table3[12, `column'] = _b[std_genderXfemale]
mat Table3[13, `column'] = -_se[std_genderXfemale]
mat Table3[14, `column'] = _b[std_otherXfemale]
mat Table3[15, `column'] = -_se[std_otherXfemale]

drop yrdum*

matlist Table3

log close
